package com.piesat.quake.business.station.api;

import com.piesat.common.vo.ResultVO;
import com.piesat.quake.business.station.model.Region;
import com.piesat.quake.business.station.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-12-07
 */
@RestController
@RequestMapping("/region")
@Api(value = "业务：区划管理", tags = "业务：区划管理")
@RequiredArgsConstructor
public class RegionController {

    private final RegionService regionService;

    @ApiOperation(value = "新增区划", notes = "新增区划")
    @PostMapping(value = "/add")
    public ResultVO addRegion(Region region) {
        regionService.addRegion(region);
        return ResultVO.success();
    }

    @ApiOperation(value = "删除区划", notes = "删除区划")
    @DeleteMapping(value = "/remove")
    public ResultVO removeRegion(String regionCode) {
        regionService.removeRegion(regionCode);
        return ResultVO.success();
    }

    @ApiOperation(value = "更新区划", notes = "更新区划")
    @PutMapping(value = "/update")
    public ResultVO updateRegion(Region region) {
        regionService.updateRegion(region);
        return ResultVO.success();
    }

    @ApiOperation(value = "查找区划列表", notes = "查找区划列表")
    @GetMapping(value = "/list")
    public ResultVO findRegionList() {
        return ResultVO.success(regionService.findRegionList());
    }

    @ApiOperation(value = "构建区划台站树", notes = "构建区划台站树")
    @GetMapping(value = "/tree")
    public ResultVO buildTree() {
        return ResultVO.success(regionService.buildTree());
    }
}

